<template>
	<view class="base-page">
		<view class="yangsf-padding-20 yangsf-flex-col-center">
			<view v-if="resObj.result == 1" class="yangsf-m-t-60 yangsf-flex-col-center">
				<u-icon name="checkmark-circle" color="#2979ff" size="28"></u-icon>
				<span style="margin-top: 20rpx;">认证成功</span>
			</view>
			<view v-else class="yangsf-m-t-60 yangsf-flex-col-center">
				<u-icon name="close-circle" color="red" size="28"></u-icon>
				<span style="margin-top: 20rpx;">认证失败，请返回重新认证</span>
			</view>

			<view class="yangsf-m-t-200 yangsf-m-b-60 yangsf-flex">
				<u-count-down :time="10 * 1000" format="ss" @finish="finish"></u-count-down>
				秒之后，自动返回首页
			</view>

			<view class="yangsf-ratio-w-60 yangsf-m-t-30">
				<u-button type="primary" :text="resObj.result == 1?'完成认证':'返回首页'" @click="submit"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		domain
	} from '@/config/config'
	import {
		submitAuthRes
	} from '@/config/api'
	export default {
		data() {
			return {
				resObj: {
					bizId: '',
					sign: '',
					msg: '',
					result: 2
				}
			}
		},
		created() {
			this.getRes()
		},
		methods: {
			submit() {
				console.log("提交认证信息");
				if (this.resObj.result && this.resObj.result == 1) {
					submitAuthRes(this.resObj).then(res => {
						if (res.code == 200) {
							window.location.href = domain
						}
					})
				} else {
					window.location.href = domain
				}
			},
			getRes() {
				let url = window.location.href;
				console.log("获取网页地址 ==> {}", url);
				if (url) {
					let temp = url.split("?")[1];
					console.log("获取参数 ==> {}", temp);
					if (temp) {
						let parts = temp.split("&");
						console.log("获取参数 parts ==> {}", parts);
						//["bizId=7df68a891d09486e87f533bfae6aadeb", "sign=lzntQY6bz48Swan7YEqbIPNaJd6IPmqEkO2HlZJza5UMhzH2JmQyJEf6wSik8gByohj2tPYmrUxqx53QfzIupA%3D%3D", "msg=%E5%A4%B1%E8%B4%A5", "result=2"]
						if (parts) {
							for (let i = 0; i < parts.length; i++) {
								const pp = parts[i].split("=");
								console.log(pp[0] + " ==> {}", pp[1]);
								if (pp && pp[0] == "bizId") {
									this.resObj.bizId = pp[1]
								} else if (pp && pp[0] == "sign") {
									this.resObj.sign = pp[1]
								} else if (pp && pp[0] == "msg") {
									this.resObj.msg = pp[1]
								} else if (pp && pp[0] == "result") {
									this.resObj.result = pp[1]
								} else if (pp && pp[0] == "serialNo") {
									this.resObj.serialNo = pp[1]
								}
							}
						}
					}
				}
			},
			finish() {
				uni.$u.toast("即将跳转首页")
				this.submit()
			}
		}
	}
</script>

<style>

</style>